// moi co 2 phan dau.anh thay bien mcount nen de o ngoai lam bien toan cuc de hon.chu xem tn nhe?
int mcount=0;
void dsmon()
{
	printf("\n\n Danh sach cac mon hoc:");
	printf("\nYear I - ACCP i7 v 1.1");
	printf("\nCF	Computer Fundamentals");
	printf("\nEPC	Elementary Programming with C");
	printf("\nHDJ	HTML, DHTML and Javascript");
	printf("\nCF	DW	Dreamweaver 8.0");
	printf("\nJAVA	Learn Java by Examples");
	printf("\nSQL1	Working with SQL Server Database Concepts");
	printf("\nSQL2	Working with SQL Server Database Concepts");

			
		
}
void add_mark()
{
	int i,j;
	char save[1],ok[1];
	char roll[10]="\0";
	char cf[10]="CF";
	char epc[10]="EPC";
	char hdj[10]="HDJ";
	char dw[10]="DW";
	char java[10]="JAVA";
	char sql1[10]="SQL1";
	char sql2[10]="SQL2";

	
		fflush(stdin);
		printf("\n-------------------------------- ");
		printf("\n Mark Information");
		printf("\n-------------------------------- ");
		printf("\n Roll No:");
		gets(roll);	
		strUpper(roll);
		printf("\n-------------------------------- ");
		for(i=0;i<scount;i++)
		{
			if (strcmp(stu[i].rollno,roll)==0)
			{
				printf("\n Student Name:%s",stu[i].name);				
				printf("\n Birthday:%s",stu[i].birth);								
				printf("\n Class:%s",stu[i].classname);
				printf("\n-------------------------------- ");
				do 
				{
					flushall();
q:					printf("\n Subject Name:");
					gets(stu[i].mark[mcount].subname);
					strUpper(stu[i].mark[mcount].subname);
					for(j=0;j<mcount;j++)
					{
						if(strcmp(stu[i].mark[mcount].subname,stu[i].mark[j].subname)==0)
						{
							printf("\n Mon nay da nhap diem!!nhap lai");
							goto q;
						}
					}
					if (strcmp(stu[i].mark[mcount].subname,cf)==0||strcmp(stu[i].mark[mcount].subname,sql1)==0) 
					{
						printf("\n Mon nay ko co thuc hanh");
t:						printf("\n Type:T");
						printf("\n Mark:");scanf("%f",&stu[i].mark[mcount].T);
						if (stu[i].mark[mcount].T>25||stu[i].mark[mcount].T<0) 
						{
							printf("\n Diem khong hop le");
							goto t;
						}
					}
					
				
					else if(strcmp(stu[i].mark[mcount].subname,cf)==0||strcmp(stu[i].mark[mcount].subname,epc)==0||strcmp(stu[i].mark[mcount].subname,hdj)==0||strcmp(stu[i].mark[mcount].subname,dw)==0||strcmp(stu[i].mark[mcount].subname,java)==0||strcmp(stu[i].mark[mcount].subname,sql2)==0)
					{
t1:						printf("\n Type:T");
						printf("\n Mark:");scanf("%f",&stu[i].mark[mcount].T);
						if (stu[i].mark[mcount].T>25||stu[i].mark[mcount].T<0) 
						{
						printf("\n Diem khong hop le");
						goto t1;
						}
t2:						printf("\n Type:P");
						printf("\n Mark:");scanf("%f",&stu[i].mark[mcount].P);
						if (stu[i].mark[mcount].P>25||stu[i].mark[mcount].P<0) 
						{
						printf("\n Diem khong hop le");
						goto t2;
						}
					
					}
					else 
					{
					printf("\n Khong co mon nay!!nhap lai");
					dsmon();
					getch();
					goto q;
					}
					printf("\n Do you want to save (y/n):");
					scanf("%s",save);
					if (strcmp(save,"n")==0)    // neu an n thi xoa bien vua nhap
					{
						strcpy(stu[i].mark[mcount].subname,stu[i].mark[mcount-1].subname);				
						stu[i].mark[mcount].T=stu[i].mark[mcount-1].T;
						stu[i].mark[mcount].P=stu[i].mark[mcount-1].P;
						mcount--;
				
					}
					
					mcount++;
					printf("\n Do you want to continue (y/n):");
					scanf("%s",ok);

				} while(strcmp(ok,"n")!=0);
			}
		}
}


void edit_mark()
{
	int i,j;
	char save[1],ok[1];
	char roll[10]="\0";
	char cf[10]="CF";
	char epc[10]="EPC";
	char hdj[10]="HDJ";
	char dw[10]="DW";
	char java[10]="JAVA";
	char sql1[10]="SQL1";
	char sql2[10]="SQL2";
	char subjectname[10];
	float lt,th;
	
	do 
	{	
		fflush(stdin);
		printf("\n-------------------------------- ");
		printf("\n Edit Student's Mark");
		printf("\n-------------------------------- ");
		printf("\n Roll No:");
		gets(roll);	
		strUpper(roll);
		printf("\n-------------------------------- ");
		for(i=0;i<scount;i++)
		{
			if (strcmp(stu[i].rollno,roll)==0)
			{
				printf("\n Student Name:%s",stu[i].name);				
				printf("\n Birthday:%s",stu[i].birth);								
				printf("\n Class:%s",stu[i].classname);
				printf("\n-------------------------------- ");
				flushall();
q:				printf("\n Input Subject Name:");
				gets(subjectname);
				strUpper(subjectname);
				if(strcmp(subjectname,cf)!=0||strcmp(subjectname,epc)!=0||strcmp(subjectname,hdj)!=0||strcmp(subjectname,dw)!=0||strcmp(subjectname,java)!=0||strcmp(subjectname,sql1)!=0||strcmp(subjectname,sql2)!=0)
				{
					printf("\n Khong co mon nay");
					dsmon();
					getch();
				}
				for(j=0;j<mcount;j++)
				if (strcmp(stu[i].mark[j].subname,subjectname)==0) 
				{
					if (strcmp(stu[i].mark[j].subname,cf)==0||strcmp(stu[i].mark[j].subname,sql1)==0) 
					{
						printf("\n Mon nay ko co thuc hanh");
						printf("\n Input Mark Type:T      Mark:%.1f",stu[i].mark[j].T);
						printf("\n Input New Mark:");scanf("%f",&lt);

					}
					else
					{
						printf("\n Mon nay co ca ly thuyet va thuc hanh");
						printf("\n Input Mark Type:T      Mark:%.1f",stu[i].mark[j].T);
						printf("\n Input New Mark:");scanf("%f",&lt);
						printf("\n Input Mark Type:P      Mark:%.1f",stu[i].mark[j].P);
						printf("\n Input New Mark:");scanf("%f",&th);
					}
				
				
					printf("\n Do you want to change (y/n):");
					scanf("%s",save);
					if (strcmp(save,"y")==0)    // neu an n thi xoa bien vua nhap
					{
						if (strcmp(stu[i].mark[j].subname,cf)==0||strcmp(stu[i].mark[j].subname,sql1)==0)
						{
							stu[i].mark[j].T=lt;
							stu[i].mark[j].P=0;
						}
						else
						{
							stu[i].mark[j].T=lt;
							stu[i].mark[j].P=th;
						}
					
					}
					if (strcmp(stu[i].mark[j].subname,cf)==0||strcmp(stu[i].mark[j].subname,sql1)==0)
					{
						printf("\n New Mark Type:T      Mark:%.1f",stu[i].mark[j].T);
					}
					else
					{					
						printf("\n New Mark Type:T      Mark:%.1f",stu[i].mark[j].T);
						printf("\n New Mark Type:P      Mark:%.1f",stu[i].mark[j].P);
					}
				}
				
				
			}
		
		}
		printf("\n Do you want to continue (y/n):");
		scanf("%s",ok);
	
	
	} while(strcmp(ok,"n")!=0);

}
//Class mark's by subject
void subject_mark()
{
	char clas[10];
	char subna[10];
	char type[1];
	int i,j;
	printf("\n Class's Mark by Subject");
	printf("\n-------------------------------------------------------------------------");
	flushall();
	printf("\n Input Class Name:");gets(clas);
	strUpper(clas);
	printf("\n Input Subject Name:");gets(subna);
	strUpper(subna);
	printf("\n Input Mark type:");gets(type);
	strUpper(type);
	printf("\n-------------------------------------------------------------------------");
	printf("\n %-15s %-30s %-10s","Roll Number","Student Name","Mark");
	printf("\n-------------------------------------------------------------------------");
	for(i=0;i<scount;i++)
	{
		if (strcmp(stu[i].classname,clas)==0)
		{
			
			for(j=0;j<mcount;j++)
			{
				if (strcmp(stu[i].mark[j].subname,subna)==0) 
				{
					
					if (strcmp(type,"T")==0)
						printf("\n %-15s %-30s %-10.1f",stu[i].rollno,stu[i].name,stu[i].mark[j].T);
					if (strcmp(type,"P")==0)
						printf("\n %-15s %-30s %-10.1f",stu[i].rollno,stu[i].name,stu[i].mark[j].P);
				}
			}
		}

	}
	printf("\n-------------------------------------------------------------------------");
	getch();

}
//Student's Average Mark 
void ave_student()
{
	char roll[10]="\0";
	int i,j;
	float sum=0,sum1=0,sum2=0;
	printf("\n Student's Average Mark");
	printf("\n----------------------------------");
	flushall();
	printf("\n Input Roll No:");gets(roll);
	strUpper(roll);
	for(i=0;i<scount;i++)
	{
		if (strcmp(stu[i].rollno,roll)==0) 
		{
			printf("\n Student Name:%s",stu[i].name);
			printf("\n Class:%s",stu[i].classname);
			printf("\n Birthday:%s",stu[i].birth);
			printf("\n----------------------------------");
			printf("\n %-10s %-10s %-10s","Subject","Theory","Practice");
			printf("\n----------------------------------");
			for(j=0;j<mcount;j++)
			{
				if(strcmp(stu[i].mark[j].subname,"CF")==0||strcmp(stu[i].mark[j].subname,"SQL1")==0)
				{
					printf("\n %-10s %-10.1f %-10s",stu[i].mark[j].subname,stu[i].mark[j].T,"none");
					sum1+=stu[i].mark[j].T/25*100;

				}
				else
				{	sum2+=stu[i].mark[j].T/25*40+stu[i].mark[j].P/25*60;
					printf("\n %-10s %-10.1f %-10.1f",stu[i].mark[j].subname,stu[i].mark[j].T,stu[i].mark[j].P);
				}
				sum=(sum1+sum2)/mcount;
				
			}
			printf("\n----------------------------------");
			printf("\n Average Mark:%.1f",sum);
		}
	}
	getch();

}

void info_mark()
{
	int ok;
	//struct_student a[100];
	
	while(ok!=6)
	{
		system("cls");
		printf("\n--------------------- ");
		printf("\n Student information");
		printf("\n--------------------- ");
		printf("\n 1. Add Student's Mark");
		printf("\n 2. Edit Student's Mark");
		printf("\n 3. Class Marks by Subject ");
		printf("\n 4. Student's Average Mark");
		printf("\n 5. Back to Main Menu");
		printf("\n 6. Exit");
		printf("\n--------------------- ");
		
		printf("\n Select the option (1-6):");
		scanf("%d",&ok);
		
		switch(ok) 
		{
		case 1:add_mark();
			break;
		case 2:edit_mark();
			break;
		case 3:subject_mark();
			break;
		case 4:ave_student();
			break;
		case 5://GoToMainMenu();
			break;
		case 6://quit();
			break;
		default:printf("chon lai");
			
		}
	} 
}





















